package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRoomJinyan;
import com.vf.admin.miaodong.entity.AppRoomLaHei;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppRoomLaHeiDao.java
 * @Description TODO
 * @createTime 2021年07月28日 19:01:00
 */
@Repository
public class AppRoomJinyanDao extends BaseDao<AppRoomJinyan> {

    public void saveOrUpdate(AppRoomJinyan pojo) {
        if (pojo.getId() == null || pojo.getId() == 0) {
            pojo.setId(this.add(pojo));
        } else {
            this.update(pojo);
        }
    }

    public List<AppRoomJinyan> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_room_jinyan where 1=1 ");
        if (StringEx.isNotNull(paramap.get("roomid"))) {
            str.append(" and roomid = ? ");
            list.add(paramap.get("roomid"));
        }
        String sql = str.toString();
        return this.queryList(sql, list, AppRoomJinyan.class, splitPageBean);
    }

    public AppRoomJinyan getByRoomidAndUserid(Integer roomid, Integer userid) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_room_jinyan where roomid = ? and userid = ? ");
        list.add(roomid);
        list.add(userid);
        String sql = str.toString();
        return this.queryObj(sql, list, AppRoomJinyan.class);
    }

    public void delete(Integer id) {
        if (id == null) {
            return;
        }
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_room_jinyan where id = ?");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }


}